<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title> UDT Reference</title>
<link rel="stylesheet" href="udtdoc.css" type="text/css" />
</head>

<body>
<div class="ref_head">&nbsp;UDT Reference: Functions</div>

<h4 class="func_name"><strong>recv</strong></h4>
<p>The <b>recv</b> method reads certain amount of data into a local memory buffer.</p>

<div class="code">int recv(<br />
&nbsp; UDTSOCKET <font color="#FFFFFF">u</font>,<br />
&nbsp; char* <font color="#FFFFFF">buf</font>,<br />
&nbsp; int <font color="#FFFFFF">len</font>,<br />
&nbsp; int <font color="#FFFFFF">flags</font><br />
);</div>

<h5>Parameters</h5>
<dl>
  <dt><i>u</i></dt>
  <dd>[in] Descriptor identifying a connected socket.</dd>
  <dt><em>buf</em></dt>
  <dd>[out] The buffer used to store incoming data.</dd>
  <dt><em>len</em></dt>
  <dd>[in] Length of the buffer.</dd>
  <dt><em>flags</em></dt>
  <dd>[in] Ignored. For compatibility only.</dd>
</dl>

<h5>Return Value</h5>
<p>On success, <b>recv</b> returns the actual size of received data. Otherwise UDT::ERROR is returned and specific error information can be retrieved by <a 
href="error.htm">getlasterror</a>. If UDT_RCVTIMEO is set to a positive value, zero will be returned if no data is received before the timer expires.</p>

<table width="100%" border="1" cellpadding="2" cellspacing="0" bordercolor="#CCCCCC">
  <tr>
    <td width="17%" class="table_headline"><strong>Error Name</strong></td>
    <td width="17%" class="table_headline"><strong>Error Code</strong></td>
    <td width="83%" class="table_headline"><strong>Comment</strong></td>
  </tr>
  <tr>
    <td>ECONNLOST</td>
    <td>2001</td>
    <td>connection has been broken and no data left in receiver buffer.</td>
  </tr>
  <tr>
    <td>ENOCONN</td>
    <td>2002</td>
    <td><i>u</i> is not connected.</td>
  </tr>
  <tr>
    <td>EINVSOCK</td>
    <td>5004</td>
    <td><i>u</i> is not an valid socket.</td>
  </tr>
  <tr>
    <td>EDGRAMILL</td>
    <td>5010</td>
    <td>cannot use <i>recv</i> in SOCK_DGRAM mode.</td>
  </tr>
  <tr>
    <td>EASYNCRCV</td>
    <td>6002</td>
    <td><i>u</i> is non-blocking (UDT_RCVSYN = false) but no data is available.</td>
  </tr>
  <tr>
    <td>ETIMEOUT</td>
    <td>6003</td>
    <td>Timeout on UDT_RCVTIMEO .</td>
  </tr>
</table>

<h5>Description</h5>
<p>The <strong>recv</strong> method reads certain amount of data from the protocol buffer. If there is not enough data in the buffer, <strong>recv</strong> only reads the available data 
in the protocol buffer and returns the actual size of data received. However, <strong>recv</strong> will never read more data than the buffer size indicates by <i>len</i>.</p>
<p>In blocking mode (default), <strong>recv</strong> waits until there is some data received into the receiver buffer. In non-blocking mode, <strong>recv</strong> returns immediately and 
returns error if no data available.</p>
<p>If UDT_RCVTIMEO is set and the socket is in blocking mode, <strong>recv</strong> only waits a limited time specified by UDT_RCVTIMEO option. If there is still no data available when 
the timer expires, error will be returned. UDT_RCVTIMEO has no effect for non-blocking socket.</p>

<h5>See Also</h5>
<p><strong><a href="send.htm">send</a>, <a href="sendfile.htm">sendfile</a>, <a href="recvfile.htm">recvfile</a></strong></p>
<p>&nbsp;</p>

</body>
</html>
